/*****************************************************************************
* File Name: trackpad_scroll_gesture.h
*
* Version: 1.0
*
* Description:
* This file contains functions and macros for detecting scroll gesture
*
* Note:
* Define DISABLE_CUSTOM_SCROLL_GESTURE in platform.h to disable the scroll 
* gestures
*
* Owner: SKUV
*
* Related Document:
* CapSense Gesture data sheet
*
* Hardware Dependency:
* Trackpad PCB
*
* Code Tested With:
* 1. PSoC Creator 3.1 
* 2. ARM GCC 4.8.4
******************************************************************************
* Copyright (2015), Cypress Semiconductor Corporation.
******************************************************************************
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
* protected by and subject to worldwide patent protection (United States and
* foreign), United States copyright laws and international treaty provisions.
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
* license to copy, use, modify, create derivative works of, and compile the
* Cypress Source Code and derivative works for the sole purpose of creating
* custom software in support of licensee product to be used only in conjunction
* with a Cypress integrated circuit as specified in the applicable agreement.
* Any reproduction, modification, translation, compilation, or representation of
* this software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 
* Cypress reserves the right to make changes without further notice to the
* materials described herein. Cypress does not assume any liability arising out
* of the application or use of any product or circuit described herein. Cypress
* does not authorize its products for use as critical components in life-support
* systems where a malfunction or failure may reasonably be expected to result in
* significant injury to the user. The inclusion of Cypress' product in a life-
* support systems application implies that the manufacturer assumes all risk of
* such use and in doing so indemnifies Cypress against all charges. Use may be
* limited by and subject to the applicable Cypress software license agreement.
*****************************************************************************/
#ifndef _TRACKPAD_SCROLL_H_
#define _TRACKPAD_SCROLL_H_

#include "stdint.h"
#include "stdbool.h"
#include "stdarg.h"
#include "stdio.h"

typedef unsigned char   uint8;
typedef unsigned short  uint16;
typedef unsigned long   uint32;
typedef signed   char   int8;
typedef signed   short  int16;
typedef signed   long   int32;
typedef          float  float32;
    
/* Macros of the gesture codes that will be detected by the scroll algorithm */
#define TRACKPAD_VERTICAL_SCROLL_UP_GESTURE                        (0x1)
#define TRACKPAD_VERTICAL_SCROLL_DOWN_GESTURE                      (0x2)
#define TRACKPAD_HORIZONTAL_SCROLL_LEFT_GESTURE                    (0x4)
#define TRACKPAD_HORIZONTAL_SCROLL_RIGHT_GESTURE                   (0x8)

/* Macro for sending various scroll counts */
#define TRACKPAD_SCROLL_COUNT_1                                     (1)
#define TRACKPAD_SCROLL_COUNT_2                                     (2)

typedef struct _Tracakpad_Scroll_Gesture_
{
    uint8 gestureMapMask;                           /* Gesture mask for the enabling the 4 scroll gestures */
    uint16 verticalStartRegion;                     /* Start of the vertical region */
    uint16 verticalEndRegion;                       /* End of the vertical region */
    uint16 verticalScrollDistance;                  /* Distance threshold for detecting the vertical scroll */
    uint32 verticalScrollTimeThreshold;             /* Time threshold for detecting the value of vertical scroll */
    uint16 horizontalStartRegion;                   /* Start of the horizontal region */
    uint16 horizontalEndRegion;                     /* End of the horizontal region */
    uint16 horizontalScrollDistance;                /* Distance threshold for detecting the horizontal scroll */
    uint32 horizontalScrollTimeThreshold;           /* Time threshold for detecting the value of horizontal scroll */
}Tracakpad_Scroll_Gesture;

#ifndef DISABLE_CUSTOM_SCROLL_GESTURE
    
/*****************************************************************************
* Function Name: Trackpad_Scroll_Gesture_Init()
******************************************************************************
* Summary:
* This function is initialises the scroll gestures algorithm  parameters
*
* Parameters:
* Tracakpad_Scroll_Gesture gestureConfig - Scroll gesture parameters 
*
* Return:
* None
* 
* Note:
* Trackpad_Scroll_Gesture_Init need to be called before calling Trackpad_Scroll_Gesture_Dection API
*****************************************************************************/
extern void Trackpad_Scroll_Gesture_Init(Tracakpad_Scroll_Gesture gestureConfig);

/*****************************************************************************
* Function Name: Trackpad_Scroll_Gesture_Dection()
******************************************************************************
* Summary:
* This function is detects the scroll gesture depending upon the finger moved on the 
* trackpad
*
* Parameters:
* uint8 numberOfFinger - Number of finger on the trackpad
* uint16 fingerPosition_x - X position of the finger in the trackpad
* uint16 fingerPosition_y - Y position of the finger in the trackpad
*
* Return:
* uint8 - Scroll gesture 
*
* Note:
* Trackpad_Scroll_Gesture_Init need to be called before calling Trackpad_Scroll_Gesture_Dection API
*****************************************************************************/
extern uint8 Trackpad_Scroll_Gesture_Dection(uint8 numberOfFinger, uint16 fingerPosition_x, uint16 fingerPosition_y);

/*****************************************************************************
* Function Name: Trackpad_Scroll_Get_ScrollCount()
******************************************************************************
* Summary:
* This function is provides the count of the last detected scroll gesture
*
* Parameters:
* None
*
* Return:
* uint8 - Scroll count of the last detected scroll gesture
*
*****************************************************************************/
extern uint8 Trackpad_Scroll_Get_ScrollCount(void);

/*****************************************************************************
* Function Name: Trackpad_IsScrollDetectionInProgress()
******************************************************************************
* Summary:
* This function is indicates whether the scroll gesture detection is in progress
*
* Parameters:
* None
*
* Return:
* bool - true if detection is in progress
*
*****************************************************************************/
extern bool Trackpad_IsScrollDetectionInProgress(void);

#else
#define Trackpad_Scroll_Gesture_Init(gestureConfig)
#define Trackpad_Scroll_Gesture_Dection(numberOfFinger, fingerPosition_x, fingerPosition_y, scrollCount) (0)
#define Trackpad_IsScrollDetectionInProgress()                                                           (false)
#endif /* DISABLE_CUSTOM_SCROLL_GESTURE */

#endif /* _TRACKPAD_SCROLL_H_ */
